//设置根目录
axios.defaults.baseURL = 'http://ajax-api.itheima.net'

const lists=document.querySelector('.top')
const fn = async () => {
  const {data:{data}} = await axios.get('/api/category/top')

const newArr=data.map( (item) => {
   return axios.get('/api/category/sub?id='+item.id)
  })

  const res = await Promise.all(newArr)
 lists.innerHTML=res.map(({data:res}) => {
   return `<li>
   <a href="javascript:;">${res.data.name}</a>
   <img
     src="${res.data.picture}"
     alt=""
   />
   <ul class="sub">
    ${res.data.children.map((item) => {
      return ` <li>
      <a href="javascript:;">
        <span>${item.name}</span>
        <img
          src="${item.picture}"
          alt=""
        />
      </a>
    </li>`
    }).join('')}
   </ul>
 </li>`
  }).join('')
}
fn()